package com.foreknow.test;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapDemo {
    public static void main(String[] args) {
        //创建一个Map集合容器
        Map<String,String> map = new HashMap<>();
        //向Map集合中添加元素
        map.put("1","one");
        map.put("2","two");
        //从Map集合中获取某个元素
        String value = map.get("2");
        System.out.println(value);
        //如何对Map集合遍历
        System.out.println("-----------------------Map集合遍历--------------------------");
        Set<Map.Entry<String,String>> set = map.entrySet();
        Iterator<Map.Entry<String,String>> it = set.iterator();
        while (it.hasNext()) {
            Map.Entry entry =it.next();
            System.out.println(entry.getKey() + "---" + entry.getValue());
        }
    }
}
